package realm;

import javax.swing.plaf.basic.BasicInternalFrameTitlePane.IconifyAction;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;

import permission.MyPermission;

public class StaticRealm extends AuthorizingRealm{
	/**
	 * 判断授权
	 */
	@Override
	protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection collection) {
		SimpleAuthorizationInfo info=new SimpleAuthorizationInfo();
		
		return null;
	}
	/**
	 * 判断认证
	 */
	@Override
	protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
		// TODO Auto-generated method stub
		String username=token.getPrincipal().toString();
		String password=new String((char[])token.getCredentials());
		if(!"kh".equals(username)) {
			throw new UnknownAccountException("用户不存在");
		}
		if(!"111".equals(password)) {
			throw new IncorrectCredentialsException("密码错误");
		}
		return new SimpleAuthenticationInfo("123@qq.com",password,getName());
	}

}
